class Solution(object):
    def countAndSay(self, n):
        s = '1'
        for _ in range(n-1):
            news = ''
            last = None
            num = 0
            for c in s:
                if c==last: 
                    num+=1
                else:
                    if last!=None:
                        news += str(num)
                        news += last
                    last=c
                    num=1
            news += str(num)
            news += last
            s = news
        return s

print(Solution().countAndSay(5))